package com.nananren.shiayn7;

public class CaesarCipher implements Strategy{
    private int shift;

    @Override
    public String encrypt(String plainText) {
       StringBuilder encrypted = new StringBuilder();
       for (char c :plainText.toCharArray()) {
           if (Character.isLetter(c)) {
               char base = Character.isUpperCase(c) ? 'A' : 'a';
               c = (char) ((c - base + shift) % 26 + base);
           }
           encrypted.append(c);
       }
       return encrypted.toString();
    }

    public CaesarCipher(int shift) {
        this.shift  = shift;
    }
}
